﻿using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace NGPT.Utils
{
    /// <summary>
    /// Implement exception logger.
    /// </summary>
    public static class Logger
    {
        private const string ULS_SOURCE = "NGPT";

        /// <summary>
        /// Log exception to ULS.
        /// </summary>
        public static void LogError(Exception ex)
        {
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    SPDiagnosticsService.Local.WriteTrace(0,
                                                      new SPDiagnosticsCategory(ULS_SOURCE, TraceSeverity.Unexpected,
                                                                                EventSeverity.Error),
                                                      TraceSeverity.Unexpected, ex.StackTrace, ex.Message);
                });
            }
            catch { };
        }

    }
}
